package com.sxx.beautifulcity.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sxx.beautifulcity.R;
import com.sxx.beautifulcity.application.ProjectApplication;

/**
 * Created by dllo on 15/10/28.
 */
public class ActivitySelectedActivity extends AppCompatActivity {


    private TextView city_name;
    private Button back_main;
    private String cityName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_city);
        city_name = (TextView) findViewById(R.id.city_name);
        back_main = (Button) findViewById(R.id.back_main);

    }

    public void goSelcet(View v) {
        startActivityForResult(new Intent(ActivitySelectedActivity.this, ActivitySelectCity.class), 99);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        try {
            switch (resultCode) {
                case 99:
                    city_name.setText(data.getStringExtra("lngCityName"));

                    cityName = city_name.getText().toString();
                    back_main.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(ProjectApplication.getContext(), MainActivity.class);
                            intent.putExtra("lngCityName", cityName);
                            startActivity(intent);
                            finish();
                            overridePendingTransition(R.anim.left_out, R.anim.right_into);
                        }
                    });
                    break;

                default:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

